#endcoding:utf-8
class AccountActivationsController < ApplicationController
  def edit
    token = params[:id]
    email = params[:email].gsub(/\%40/, '@')
    @user = User.find_by(email:email)
    if @user && !@user.activated? && @user.authenticated?(:activation,token)
      @user.update_attribute(:activated, true)
      @user.update_attribute(:activated_at, Time.zone.now)
      log_in @user
      flash[:success] = "账号成功激活!"
      redirect_to @user
    else
      flash[:danger] = "无效的激活链接"
      redirect_to root_url
    end
  end
end
